// Author: wsfuyibing <682805@qq.com>
// Date: 2025-04-11

package gen_anno

import (
	"context"
	"gitee.com/go-libs/console"
	"gitee.com/go-wares/framework-gin/framework/commands"
)

const (
	cmdDesc = "Generate application annotation files"
	cmdName = "gen:anno"
)

var (
	cmdOptions = map[string]*commands.Option{}
)

type Provider struct {
	cmd *console.Command
}

func (o *Provider) Before(ctx context.Context, container *console.Container, cmd *console.Command) (err error) {
	return
}

func (o *Provider) Run(ctx context.Context, container *console.Container, cmd *console.Command) (err error) {
	return
}

func (o *Provider) init() *Provider {
	o.cmd = console.NewCommand(cmdName).SetDescription(cmdDesc).SetProvider(o)
	o.initOptions()
	return o
}

func (o *Provider) initOptions() {
	for name, option := range cmdOptions {
		if option == nil {
			return
		}
		opt := console.NewOption(name).
			SetDescription(option.Description).
			SetKind(option.Kind).
			SetRequired(option.Required)
		if option.Short > 0 {
			opt.SetShortName(option.Short)
		}
		if option.DefaultValue != nil {
			opt.SetDefaultValue(option.DefaultValue)
		}
		o.cmd.Add(opt)
	}
}

func New() *console.Command {
	return (&Provider{}).init().cmd
}
